<script>
    layui.use(['layer', 'table', 'form'], function () {
        var table = layui.table;

        var dataTable = table.render({
            elem: '#dataTable'
            , height: 500
            , url: "{{ route('admin.system.database.backup.data') }}"
            , page: true
            , cols: [[
                {field: 'id', title: 'ID', width: 80, templet: '#auto'}
                , {field: 'name', title: '名称'}
                , {fixed: 'right', title: '操作', width: 220, align: 'center', toolbar: '#options'}
            ]]
        });

        $('#backup').click(function () {
            $.post("{{ route('admin.system.database.backup.execute') }}", {
                _method: 'post'
            }, function (result) {
                if (result.code == 0) {
                    dataTable.reload();
                }
                layer.msg(result.msg);
            });
        });

        table.on('tool(dataTable)', function (obj) {
            var data = obj.data;
            var event = obj.event;
            if (event === 'delete') {
                layer.confirm('确认删除吗？', function (index) {
                    $.post("{{ route('admin.system.database.backup.delete') }}", {
                        _method: 'delete',
                        id: data.id
                    }, function (result) {
                        if (result.code == 0) {
                            dataTable.reload()
                        }
                        layer.close(index);
                        layer.msg(result.msg);
                    });
                });
            }
        });
    });
</script>